$(document).ready(function(){
	var type=$('#type').val();
	var pId=$('#pId').val();
	genDictSelect('sexInfo','sex','1');
	genDictSelect('nationCode','nation','1');
	genDictSelect('nationalityCode','nationality','1');
	genDictSelect('medicalType','medical_type','1');
	initForm(type,pId);
	//事件绑定
	eventBind(type,pId);
});
//初始化form表单
function initForm(type,pId){
	$('#patientForm1').validation();
	
	if(pId==''){
		
	}else{
		$.getApiClient('/patient/select/{id}').setQuery({id: pId}).get().done(function(data){
			debugger;
			if(data.code=='0'){
				var payload=data.payload;
				$('#patientForm1').bindData(payload);
				genDictSelect('sexInfo','sex',payload.sex);
				genDictSelect('nationCode','nation',payload.nation);
				genDictSelect('nationalityCode','nationality',payload.nationality);
				genDictSelect('medicalType','medical_type',payload.medical_type);
			}
		})
	}
}
//事件绑定
function eventBind(type,pId){
	$('#cancel').click(function(){
		BootstrapDialog.closeAll();
	})
	if(pId==''){
		$('#save').on('click',saveNewPatient);
	}else{
		$('#save').on('click',function(){
			updatePatient(pId);
		});
	}
}